/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ca.usask.cs.SimulationModel;

import java.util.Iterator;
import java.util.LinkedList;

import ca.usask.cs.decisiontree.api.Edge;


/**
 *
 * @author tonyleung
 */
public class VensimActionStack implements ModelingAgentActionStackInterface{

    LinkedList<ModelingAgentObjectInterface> venActionStack;

    public VensimActionStack()
    {
        this.venActionStack = new LinkedList<ModelingAgentObjectInterface>();
    }

    /**
     * Adds to the top of the stack an modelingAgentObject created from theEdge
     * @param theEdge
     */
    public void push(ModelingAgentObjectInterface modelingAgentObject)
    {
        this.venActionStack.add(modelingAgentObject);
    }


    /**
     * retrieves the first modelingAgentObject from the stack
     *      if the stack is empty, return null
     * @return
     */
    public ModelingAgentObjectInterface pop()
    {
        if(this.venActionStack.isEmpty())
        {
            return null;
        }
        return this.venActionStack.removeLast();
    }

    /**
     * retrieves the stack of modelingAgentObjects in an iterator
     * @return
     */
    public Iterator<ModelingAgentObjectInterface> getList()
    {
        return venActionStack.iterator();
    }

    /**
     * retrieves the time value for the last modelingAgentObject
     *      if venActionStack is empty, return negative infinity.
     * @return
     */
    public double getFinalTime()
    {
        if(this.venActionStack.isEmpty())
        {
            return Double.NEGATIVE_INFINITY;
        }

        return this.venActionStack.getLast().getTime();
    }
}
